package com.qf.smartplatform.controller;

import com.qf.smartplatform.dto.R;
import com.qf.smartplatform.dto.UserDto;
import com.qf.smartplatform.pojo.SysUserInfo;
import com.qf.smartplatform.service.UserService;
import com.qf.smartplatform.valigroup.insert;
import com.qf.smartplatform.valigroup.select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/users")
public class UserController {
    private UserService userService;
    @Autowired
    public void setUesrService(UserService userService) {
        this.userService = userService;
    }

    @PostMapping("/registry")
    public R register (@Validated(insert.class) @RequestBody UserDto userDto){
        userService.addUser(userDto);
        return R.OK();
    }
//    @PostMapping("/login")
//    public R login(@Validated(select.class)@RequestBody UserDto userDto , HttpSession session){
//        //获取到ip地址
////        String remoteHost = request.getRemoteHost();
////        System.out.println("ip地址为++++++++++++++++++++"+remoteHost);
//        SysUserInfo sysUserInfo = userService.login( userDto.getUsername(),userDto.getPassword());
//        session.setAttribute("user",sysUserInfo);
//    return R.OK();
//    }
}
